//*****************************************************************************
// JFab (http://code.google.com/p/jfab)
// Copyright (c) 2011-2012 JFab.org
// Admin jfab@jeffreythompson.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package org.jfab.core.collection;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.jfab.core.model.CGObject;

/**
 * Provides base functionality for a code generator object list.
 * 
 * @param <T> Type.
 */
public abstract class CGObjectList<T extends CGObject> extends CGList<T>
{
    /**
     * Construct this object with the given parameter.
     * 
     * @param list List.
     */
    protected CGObjectList(final List<T> list)
    {
        super(list);
    }

    /**
     * @param name Object name.
     * 
     * @return the object with the given name.
     */
    public T findByName(final String name)
    {
        T answer = null;

        if (StringUtils.isNotEmpty(name))
        {
            final int size = getList().size();

            for (int i = 0; (answer == null) && (i < size); i++)
            {
                final T cgObject = getList().get(i);

                if (name.equals(cgObject.getName()))
                {
                    answer = cgObject;
                }
            }
        }

        return answer;
    }
}
